package com.damn;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class URLResponse {

	/**
	 * @param args
	 */
	public StringBuffer getURLResponse(String destURL)	{
		StringBuffer responseStr = new StringBuffer();
		URL url;		
		HttpURLConnection connection = null;
		try	{
		  url = new URL(destURL);
	      connection = (HttpURLConnection)url.openConnection();
	      connection.setRequestMethod("POST");
	      connection.setRequestProperty("Content-Type", 
	           "application/x-www-form-urlencoded");
				
	      connection.setRequestProperty("Content-Length", "" +"0");
	      connection.setRequestProperty("Content-Language", "en-US");  
				
	      connection.setUseCaches (false);
	      connection.setDoInput(true);
	      connection.setDoOutput(true);
	      
	      
	      //Send request
	      DataOutputStream wr = new DataOutputStream (
	                  connection.getOutputStream ());
	      ///wr.writeBytes (urlParameters);
	      wr.flush ();
	      wr.close ();
		
	      
	      //Get Response	
	      InputStream is = connection.getInputStream();
	      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
	      String line;
	       
	      while((line = rd.readLine()) != null) {
	        responseStr.append(line);
	        responseStr.append('\r');
	      }
	      rd.close();	      

	    } catch (Exception e) {

	      e.printStackTrace();    

	    } finally {

	      if(connection != null) {
	        connection.disconnect(); 
	      }
	    }
		return responseStr;
	}
}
